package cn.mengfly.fxtest.util;

import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;

import java.lang.reflect.Field;

/**
 * @author Mengfly
 * @date 2021/5/28 15:10
 */
public class UiUtil {

    public static  <T> void initTable(TableView<T> tblItems, Class<? super T> itemClass) {
        Field[] declaredFields = itemClass.getDeclaredFields();
        for (Field declaredField : declaredFields) {
            TableColumn<T, ?> tableColumn = new TableColumn<>(declaredField.getName());
            tableColumn.setCellValueFactory(new PropertyValueFactory<>(declaredField.getName()));
            tblItems.getColumns().add(tableColumn);
        }
    }
}
